package com.nit.store.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nit.store.mapper.DistrictMapper;
import com.nit.store.pojo.dto.output.DistrictDto;
import com.nit.store.pojo.entity.DictDistrict;
import com.nit.store.util.CommonUtils;
import com.nit.store.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author J1ay
 * @Date 2022/7/21 20:13
 * @Description
 */
@RestController
@RequestMapping("/districts")
@Slf4j
public class DistrictController {
    @Autowired
    DistrictMapper districtMapper;

    @GetMapping("/")
    public JsonResult<List<DistrictDto>> getDistrict(String parent) {
        QueryWrapper<DictDistrict> wrapper = new QueryWrapper<>();
        wrapper.eq("parent", parent);
        List<DictDistrict> data = districtMapper.selectList(wrapper);
        return JsonResult.ok(CommonUtils.getMapperFacade().mapAsList(data, DistrictDto.class));
    }
}
